<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<%@ attribute name="name" required="true" rtexprvalue="true" description="name of text element"%>
<%@ attribute name="label" required="false" rtexprvalue="true" description="Label of text element"%>
<%@ attribute name="bindPath" required="true" rtexprvalue="true" description="Bind path of text element"%>
<%@ attribute name="total" required="true" rtexprvalue="true" description="Total of input element" type="java.lang.Integer"%>
<%@ attribute name="widgetType" required="false" rtexprvalue="true" description="WidgetType of text element"%>
<%@ attribute name="id" required="false" rtexprvalue="true" description="ID of text input element"%>
<%@ attribute name="widgetAttrs" required="false" rtexprvalue="true" description="WidgetAttrs of text element"%>
<%@ attribute name="cssStyle" required="false" rtexprvalue="true" description="CSS Style of form element"%>
<%@ attribute name="cssLabelStyle" required="false" rtexprvalue="true" description="CSS Style of label grid"%>
<%@ attribute name="cssElementlStyle" required="false" rtexprvalue="true" description="CSS Style of element grid"%>
<%@ attribute name="hiddenLabel" required="false" rtexprvalue="true" description="Hidden Label" type="java.lang.Boolean"%>
<%@ attribute name="disableRadio" required="false" rtexprvalue="true" description="Hidden 'All' Radiobox" type="java.lang.Boolean"%>
<%@ attribute name="radioBindPath" required="false" rtexprvalue="true" description="Bind path for 'All' Radiobox" type="java.lang.String"%>
<%@ attribute name="radioLabel" required="false" rtexprvalue="true" description="Label for 'All' Radiobox" type="java.lang.String"%>
<%@ attribute name="radioValue" required="false" rtexprvalue="true" description="Value for 'All' Radiobox" type="java.lang.String"%>

<c:choose>
	<c:when test="${label == null || label == ''}">
		<c:set var="label" value="${name}" />
	</c:when>
</c:choose>
<c:choose>
  <c:when test="${id == null || id == ''}">
    <c:set var="id" value="${name}" />
  </c:when>
</c:choose>
<c:choose>
  <c:when test="${widgetType == null || widgetType == ''}">
    <c:set var="widgetType" value="dijit.form.ValidationTextBox" />
  </c:when>
</c:choose>
<c:if test="${radioBindPath == null || radioBindPath == ''}">
    <c:set var="radioBindPath" value="${bindPath}All" />
</c:if>
<c:if test="${radioLabel == null || radioLabel == ''}">
    <c:set var="radioLabel" value="ALL" />
</c:if>
<c:if test="${radioValue == null || radioValue == ''}">
    <c:set var="radioValue" value="X" />
</c:if>

<c:if test="${!hiddenLabel}">
	<li class="form_grid_label" style="${cssLabelStyle}"><label for="${name}">${label}:</label></li>
	<li class="form_grid_element" style="${cssElementlStyle}">
</c:if>
<c:if test="${!disableRadio}">
  <form:radiobutton id="${id}All" path="${radioBindPath}" label="${radioLabel} " value="${radioValue}"/> 
  <form:radiobutton id="${id}Set" path="${radioBindPath}" label="" value=""/>
  <script type="text/javascript">
    Spring.addDecoration(new Spring.ElementDecoration(
            {
              elementId : '${id}All',
              widgetType : "dijit.form.RadioButton",
              widgetModule : "dijit.form.CheckBox",
              widgetAttrs : {
                value : "X"
              }
            }));
    Spring.addDecoration(new Spring.ElementDecoration(
            {
              elementId : '${id}Set',
              widgetType : "dijit.form.RadioButton",
              widgetModule : "dijit.form.CheckBox",
              widgetAttrs : {
                value : ""
              }
            }));
  </script>
</c:if>
  <c:if test="${total == 1}">
  <form:input id="${id}" path="${bindPath}" cssStyle="${cssStyle}"/> <script type="text/javascript">
    Spring.addDecoration(new Spring.ElementDecoration({
      elementId : "${id}",
      widgetType : "${widgetType}"
      <c:if test="${widgetAttrs != null}">,widgetAttrs : {${widgetAttrs}}</c:if>
    }));
  </script>
  </c:if>
  <c:if test="${total > 1}">
  <c:forEach var="index" begin="0" end="${total - 1}">
	<form:input id="${id}${index}" path="${bindPath}${index}" cssStyle="${cssStyle}"/>
  <script type="text/javascript">
		Spring.addDecoration(new Spring.ElementDecoration({
			elementId : "${id}${index}",
			widgetType : "${widgetType}",
			<c:if test="${widgetAttrs != null}">widgetAttrs : {	${widgetAttrs}}  </c:if>
		}));
	</script>
	</c:forEach>
	</c:if>
<c:if test="${!hiddenLabel}">
</li>
</c:if>

	